﻿@model Article
@{
    Ajax.Dna().Widget()
        .UserPreferences(@<text>
    @(
 Ajax.Dna().TreeView(item.GenerateFieldID("PostTree"))
                    .SinglePathExpand(true)
                    .Options(opts =>
                    {
                        opts.NodeSelectedCssClass = "";
                        opts.OnNodePopulate = (new System.Text.StringBuilder())
                            .Append("var $n = $(node);")
                            .Append("$n.addClass(\"d-treenode-loading\");")
                            .Append("var url = $(\">.d-treenode-content>a\", $n).attr(\"rel\");")
                            .Append("$(\"#" + item.GenerateFieldID("PostTree") + "\").dtree(\"loadNodes\", url, \"POST\", {}, $n);")
                            .Append("$n.removeClass(\"d-treenode-hasChildren\");")
                            .ToString();
                        opts.OnNodeLoaded = "if (node) { $(node).removeClass(\"d-treenode-loading\"); } ";
                        opts.OnNodeSelected = "$(\"#" + item.GenerateFieldID("PostID") + "\").val($(\">.d-treenode-content>a>input\",node).val()) ";
                    })
                    .HtmlAttributes(new { style = "overflow:auto;height:200px;" })
                    .ClientBind(Url.Action("GetNodes", "Library", new { Area = "Publishing", id = 0 }))
                    .ClientNodeTemplate(_item =>
                    {
                        return new HelperResult(writer =>
                        {
                            writer.Write("<li {{if hasChildren}} class=\"d-treenode-hasChildren\" {{/if}}><a href=\"javascript:void(0);\" {{if rel}} rel=\"${rel}\" {{/if}}>");
                            writer.Write("<input type=\"hidden\" value=\"${id}\"/>");
                            writer.Write("<img src=\"${imgUrl}\" class=\"d-treenode-img\" alt=\"${title}\" /><span class=\"d-treenode-text\">${title}</span> </a></li>");
                        });
                    }).GetHtml()
                           )
    <input id="@item.GenerateFieldID("PostID")" name="@item.GenerateFieldID("PostID")" type="hidden" value="@item.GetInt("PostID")"/>
    @Ajax.Dna().Checkbox(item.GenerateFieldID("ShowTitle"), Html.Global("ShowPostTitle"), item.GetBool("ShowTitle")).GetHtml()
    </text>)
        .Content(@<text> 
    @if (Model != null)
    {
        var article = new ArticleWrapper(Model);
        var _content = article.GetGlobalizationContent();

        if (item.GetBool("ShowPostTitle"))
        {
        <h1 class="dna-post-title">
            @_content.Title @Publishing.PostStateImage(Model, Url)
        </h1>
        <hr />
        <ul class="d-horizontal-list">
            <li>
                @{ Html.RenderPartial("_Tagged", Model); }
            </li>
            <li>
                @{ Html.RenderPartial("_FiledUnder", article.AllCategories()); }
            </li>
            <li>
                @Ajax.Dna().Link("#commentlist").Text(article.Comments.Count.ToString()).ToolTip(Html.Global("publishing", "GoToComments")).ImageIcons(Url.Content("~/Content/Images/comments.gif")).GetHtml()
            </li>
        </ul>
        }
        
        if (string.IsNullOrEmpty(Model.Password) || (Request.IsAuthenticated && (User.Identity.Name.Equals(article.Author.UserName, StringComparison.OrdinalIgnoreCase))))
        {
            Html.RenderPartial("_ContentBody", Model);
        }
        else
        {
            Html.RenderAction("UnlockConent", "Article", new { Area = "Publishing", id = Model.ID });
        }
    }
    </text>)
        .Render();
}
